﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Extensions;
using ConfExpert.Utility;

namespace Tailord
{
    public partial class IrsaliyeOlustur : XPopupForm
    {
        int irsaliyeNo;
        bool isProva = false;
        
        public bool IsProva
        {
            get { return isProva; }
        }

        public int IrsaliyeNo
        {
            get { return irsaliyeNo; }
        }


        public IrsaliyeOlustur(bool IsProva)
        {
            InitializeComponent();
            cbProva.Visible = IsProva;

        }

        private void FaturaOlustur_Load(object sender, EventArgs e)
        {
            HeaderPanel.Visible = MainToolbar.Visible = lblHata.Visible = false;
            txtFatura.Focus();

            btnFatura.Click += btnFatura_Click;
            cbProva.CheckedChanged += cbProva_CheckedChanged;
        }

        void cbProva_CheckedChanged(object sender, EventArgs e)
        {
            isProva = cbProva.Checked;
        }


        void btnFatura_Click(object sender, EventArgs e)
        {
            lblHata.Visible = false;
            irsaliyeNo = txtFatura.Text.ToIntZero();
            if (irsaliyeNo==0)
            {
                lblHata.Text = "Lütfen fatura numarası girin";
                lblHata.Visible = true;
                return;
            }
            else if (irsaliyeNo>0)
            {
                int isOk = AppSession.DataManager.ExecuteScalar("KontrolIrsaliyeNo", irsaliyeNo).ToIntZero();
                if (isOk == 1)
                {
                    lblHata.Text = "Belirttiğiniz irsaliye daha önceden kesilmiş";
                    lblHata.Visible = true;
                    return;
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }

    }
}